@extends('layout.admin.master')
@section('content')
    <form action="" method="post">
        <div class="card">
            <div class="card-body">
                <ul class="nav nav-tabs nav-tabs-sm">
                    <li class="nav-item">
                        <a href="{{route('permission.user.index')}}" class="nav-link active">
                            用户列表
                        </a>
                    </li>
                    <li class="nav-item">
                        <a href="{{route('permission.user.create')}}" class="nav-link ">
                            添加用户分类
                        </a>
                    </li>
                </ul>
                <table class="table">
                    <thead>
                    <tr>
                        <th>编号</th>
                        <th>用户名</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    @foreach($users as $user)
                    <tr>
                        <td scope="row">{{$user->id}}</td>
                        <td>{{$user->name}}</td>
                        <td>
                            {{--@can('')--}}
                            <a href="{{route('permission.role.setPermission',$user)}}" class="btn btn-success btn-sm">设置角色</a>
                            @can('update',$user)
                            <a href="{{route('permission.user.edit',$user)}}" class="btn btn-primary btn-sm">编辑</a>
                            @endcan
                            <a href="{{route('permission.user.show',$user)}}" class="btn btn-info btn-sm">查看</a>
                            @can('delete',$user)
                            <a href="javascript:;" onclick="del(this)" class="btn btn-danger btn-sm">删除</a>
                            @endcan
                            <form action="{{route('permission.user.destroy',$user)}}" method="post">
                                @csrf
                                @method('DELETE')
                            </form>
                        </td>
                    </tr>
                        @endforeach
                    </tbody>
                </table>
            </div>
            <div class="card-footer text-muted">
               底部
            </div>
        </div>
    </form>
@endsection
@push('js')
    <script>
        function del(obj) {
            require(['https://cdnjs.cloudflare.com/ajax/libs/sweetalert/2.1.0/sweetalert.min.js'], function (swal) {
                swal({
                    text: "确定删除吗?",
                    buttons: {
                        cancel: "取消",
                        defeat: '确定',
                    },
                }).then((value) => {
                    switch (value) {
                        case "defeat":
                            $(obj).next('form').trigger('submit');
                            break;
                    }
                });
            })
        }
    </script>
@endpush
